import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:lepig/model/PageInfoModel.dart';
import 'package:lepig/model/ProductModel.dart';
import 'package:lepig/model/SelectProductTypeModel.dart';
import 'package:lepig/request/lib/HttpManager.dart';

import 'lib/NWApi.dart';
import 'lib/NWMethod.dart';

/**
 * 获取分类
 */

// ignore: non_constant_identifier_names
Future<List<ProductModel>> HttpSelectSearchProduct(BuildContext context,{int page=1,String q,String type,String cid,bool isCoupon,String sort}) async {
  List<ProductModel> lists = new List<ProductModel>();

  Map<String, dynamic> data = new Map<String, dynamic>();
  data["q"] = q;
  data["type"] = type;
  data["sort"] = sort;
  if(isCoupon!=null&&isCoupon){
    data["isCoupon"] = isCoupon.toString();
  }
  data["pageSize"] = "10";
  data["pageNum"] = page.toString();
  print(data.values.toString());
  Map responseBody = await HttpManager()
      .request(NWApi.selectSearchProduct, NWMethod.GET,params: data);
  List<dynamic> list = responseBody['data']["list"];
  list.forEach((element) {
    lists.add(ProductModel.fromJson(element));
  });
  return lists;
}
